﻿using Lis.Data;
using Lis.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Lis.KISSFRSTDAL
{
    /// <summary>
    /// 职责：BaseDal封装了所有Dal的公共的增删查改
    /// 类的职责一定要单一
    /// </summary>
    public abstract class BaseDal<T> where T : class,new()//封装T，1，表明是个类。2，有默认的构造函数
    {
        public Dao DB { get { return Dao.Get(); } }

        #region 01，新增+bool Add(T t)
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public bool Add(T t)
        {
            return DB.Insert<T>(t) > 0;
        }
        #endregion

        #region 02，更新+bool Update(T t)
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public virtual bool Update(T t)
        {

            return DB.Update<T>(t) > 0;
        }
        #endregion

        #region 03，删除+ bool Delete(T t)
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="t">实体模型</param>
        /// <returns></returns>
        public virtual bool Delete(T t)
        {
            return DB.Delete<T>(t) > 0;
        }
        #endregion

        #region 04，分页查询+abstract IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, bool isAsc, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="total">总条数</param>
        /// <param name="isAsc">是否倒叙</param>
        /// <param name="whereLambda">查询lambda</param>
        /// <param name="orderByLambda">排序lambda</param>
        /// <returns></returns>
        public abstract IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, bool isAsc, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda);
        #endregion
    }
}
